//
// Created by bwsc-004 on 2018/12/20.
//

#ifndef WEBSRV_BW_XML_H
#define WEBSRV_BW_XML_H

#include "tinyxml.h"
#include "tinystr.h"
#include "bw_FcgiRequest.h"

using namespace std;

inline void TINY_XML_GET_STR_ATTR(TiXmlElement *element, const char *attr, string &dst, const char *defVal) {
    dst.clear();
    if ((nullptr == element) || (nullptr == attr)) {
        return;
    }
    dst = (nullptr == element->Attribute(attr)) ? defVal : element->Attribute(attr);
}

inline void TINY_XML_GET_INT_ATTR(TiXmlElement *element, const char *attr, int &dst, int defVal) {
    if ((nullptr == element) || (nullptr == attr)) {
        return;
    }
    dst = (nullptr == element->Attribute(attr)) ? defVal : (int)atof(element->Attribute(attr));
}

inline void TINY_XML_GET_DOUBLE_ATTR(TiXmlElement *element, const char *attr, double &dst, double defVal) {
    if ((nullptr == element) || (nullptr == attr)) {
        return;
    }
    dst = (nullptr == element->Attribute(attr)) ? defVal : atof(element->Attribute(attr));
}

#endif //WEBSRV_BW_XML_H
